import {Subject, from, Observable} from "rxjs";
import {fromArray} from "rxjs/internal/observable/fromArray";
import {multicast} from "rxjs/internal/operators";
/**
 * Created by ztt on 2018/12/9.
 */
/**todo:Subject
 */
function fun01(){
    var subject01=new Subject();
    subject01.subscribe({
        next: (v:any) => console.log('observer01A: ' + v)
    });
    subject01.subscribe({
        next: (v:any) => console.log('observer01B: ' + v)
    });

    subject01.next(1);
    subject01.next(2);
}

function fun02(){
    var subject=new Subject();
    subject.subscribe({
        next:(v:any)=>console.log('objser02:',v),
        complete:()=>console.log('observer02- - - complete：'),
        error:(error:any)=>console.log('error：',error)
    });
    var source=fromArray([1,2,3,4]);
    source.subscribe(subject);
}
/**todo:
 * multicast !!!!!!!!!!!!!!!!!!!
 * connect() !!!!!!!!!!!!!!!!!!!
 **/
function fun03(){
    var source=fromArray([1,2,3,4]);
    var subject = new Subject();
    var multicasted = multicast(subject);
    // 在底层使用了 `subject.subscribe({...})`:
    // subject.subscribe({
    //     next: (v:any) => console.log('observerA: ' + v)
    // });
    // subject.subscribe({
    //     next: (v:any) => console.log('observerB: ' + v)
    // });
    // 在底层使用了 `source.subscribe(subject)`:
    // source.subscribe(multicasted);

}